<template>
    <div class="xing-date">
      <el-form :inline="true" :model="dataForm">
        <el-form-item label="当月日期范围">
          <el-date-picker
            v-model="dataForm.monthDate"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="~"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="最近14天日期">
          <el-date-picker
            :picker-options="pickerOptions"
            value-format="yyyy-MM-dd HH:mm:ss"
            format="yyyy-MM-dd HH:mm:ss"
            v-model="dataForm.recentDate"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
import { getFirstAndLastMonthDay, formatDefaultDate } from '../../utils/tools'
export default {
  name: 'Date',
  data () {
    return {
      dataForm: {
        monthDate: [],
        recentDate: []
      },
      pickerOptions: {
        disabledDate (date) {
          let zero = new Date()
          return date.getTime() > zero
        }
      }
    }
  },
  created () {
    // 获取当前月第一天到最后一天
    this.dataForm.monthDate = getFirstAndLastMonthDay()
    this.handleDefault()
  },
  methods: {
    // 获取最近14天日期
    handleDefault () {
      let today = formatDefaultDate(new Date())
      let before14Day = formatDefaultDate(new Date(new Date().getTime() - 3600 * 1000 * 24 * 14))
      this.dataForm.recentDate = [before14Day, today]
    }
  }
}
</script>

<style scoped>

</style>
